home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / processes / mp threaded sort / dragutils.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.4 KB  |  80 lines

  1. /*
  2.     File:        DragUtils.cp
  3.  
  4.     Contains:    Useful utility functions when using the Drag Manager.
  5.  
  6.     Written by: Dave Falkenburg    and Cameron Esfahani
  7.  
  8.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/27/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 11/12/94    DRF                Added #include to pick up function prototype.
  21.  
  22. */
  23. #include "Sprocket.h"
  24.  
  25. #include <Folders.h>
  26.  
  27. Boolean
  28. DragDestinationIsTheTrash(DragReference theDrag)
  29.     {
  30.     AEDesc    dropLocation;
  31.     AEDesc    dropFSSpecDesc;
  32.     Boolean    wasItDraggedToTrash = false;
  33.     OSErr    err;
  34.  
  35.     err = GetDropLocation(theDrag, &dropLocation);
  36.     if (err != noErr)
  37.         return false;
  38.  
  39.     if ((dropLocation.descriptorType != typeNull) && 
  40.         (AECoerceDesc(&dropLocation, typeFSS, &dropFSSpecDesc) == noErr))
  41.         {
  42.         FSSpec *        theDropFSSpec;
  43.         CInfoPBRec        theCatInfoPB;
  44.         long            trashDirID;
  45.         short            trashVRefNum;
  46.  
  47.         //    If we got here, the drag went to a file system thing
  48.         
  49.         HLock(dropFSSpecDesc.dataHandle);
  50.         theDropFSSpec = (FSSpec *) *dropFSSpecDesc.dataHandle;
  51.             
  52.         theCatInfoPB.dirInfo.ioCompletion = nil;
  53.         theCatInfoPB.dirInfo.ioNamePtr = (StringPtr) &theDropFSSpec->name;
  54.         theCatInfoPB.dirInfo.ioVRefNum = theDropFSSpec->vRefNum;
  55.         theCatInfoPB.dirInfo.ioFDirIndex = 0;
  56.         theCatInfoPB.dirInfo.ioDrDirID = theDropFSSpec->parID;
  57.         if (PBGetCatInfoSync(&theCatInfoPB) != noErr)
  58.             goto bail;
  59.  
  60.         //    Is it a directory?
  61.  
  62.         if (!(theCatInfoPB.dirInfo.ioFlAttrib & ioDirMask))
  63.             goto bail;
  64.         
  65.         //    Is it the trash folder?
  66.         
  67.         (void) FindFolder(kOnSystemDisk,kTrashFolderType,kCreateFolder,&trashVRefNum,&trashDirID);
  68.  
  69.         if ((theDropFSSpec->vRefNum == trashVRefNum) && (theCatInfoPB.dirInfo.ioDrDirID == trashDirID))
  70.             wasItDraggedToTrash = true;
  71.         }
  72.  
  73. bail:
  74.     HUnlock(dropFSSpecDesc.dataHandle);
  75.     AEDisposeDesc(&dropFSSpecDesc);
  76.     AEDisposeDesc(&dropLocation);
  77.  
  78.     return wasItDraggedToTrash;
  79.     }
  80.